<script setup lang="ts">
import { LoginForm, RegisterForm, ResetForm } from './components'
import { ThemeSwitch } from '@/components/ThemeSwitch'
// import { LocaleDropdown } from '@/components/LocaleDropdown'
import { useI18n } from '@/hooks/web/useI18n'
import { underlineToHump } from '@/utils'
import { useAppStoreWithOut } from '@/store/modules/app'
import { useBasicStoreWithOut } from '@/store/modules/basic'
import { useDesign } from '@/hooks/web/useDesign'
import { ref } from 'vue'

const { getPrefixCls } = useDesign()

const prefixCls = getPrefixCls('login')

const basicStore = useBasicStoreWithOut()
const appStore = useAppStoreWithOut()

const { t } = useI18n()

// 0登录，1注册，2找回密码
const pageStatus = ref(0)

const toRegister = () => {
  pageStatus.value = 1
}

const toReseter = () => {
  pageStatus.value = 2
}

const toLogin = () => {
  pageStatus.value = 0
}
</script>

<template>
  <div
    :class="prefixCls"
    class="login-bg h-[100%] relative <xl:bg-v-dark <sm:px-10px <xl:px-10px <md:px-10px"
    :style="
      basicStore.getLogin?.background
        ? 'background-image:url(' + basicStore.getLogin?.background + ')'
        : ''
    "
  >
    <div class="relative h-full flex mx-auto">
      <div
        v-if="basicStore.getLogin?.panelPosition != 'center'"
        :class="
          `${prefixCls}__left flex-1 relative p-30px <xl:hidden` +
          ` ${
            !basicStore.getLogin?.boximage &&
            (basicStore.getLogin?.subTitle || basicStore.getHeader?.subTitle)
              ? 'flex items-center justify-center'
              : ''
          }`
        "
      >
        <div
          class="flex items-center relative text-white"
          v-if="
            !basicStore.getLogin?.boximage &&
            (basicStore.getLogin?.subTitle || basicStore.getHeader?.subTitle)
          "
        >
          <img :src="basicStore.getHeader?.image" alt="" class="h-32px mr-10px" />
          <div>
            <span class="text-28px font-bold">{{
              basicStore.getLogin?.title ||
              basicStore.getHeader?.title ||
              underlineToHump(basicStore.getTitle)
            }}</span>
            <div :class="basicStore.getHeader?.image ? '' : 'text-center'" class="mt-2">{{
              basicStore.getLogin?.subTitle || basicStore.getHeader?.subTitle
            }}</div>
          </div>
        </div>
        <div v-else class="flex items-center relative text-white">
          <img :src="basicStore.getHeader?.image" alt="" class="h-32px mr-10px" />
          <span class="text-20px font-bold">{{
            basicStore.getLogin?.title ||
            basicStore.getHeader?.title ||
            underlineToHump(basicStore.getTitle)
          }}</span>
        </div>
        <div
          class="flex justify-center items-center h-[calc(100%-60px)]"
          v-if="!basicStore.getLogin?.background"
        >
          <TransitionGroup
            appear
            tag="div"
            enter-active-class="animate__animated animate__bounceInLeft"
          >
            <img
              v-if="basicStore.getLogin?.boximage"
              :src="basicStore.getLogin?.boximage"
              key="2"
              alt=""
              class="w-350px"
            />
            <img v-else src="@/assets/svgs/login-box-bg.svg" key="1" alt="" class="w-350px" />
            <div class="text-3xl text-white" key="2">{{
              basicStore.getLogin?.welcome || t('login.welcome')
            }}</div>
            <div class="mt-5 font-normal text-white text-14px" key="3"> </div>
          </TransitionGroup>
        </div>
      </div>
      <div class="flex-1 p-30px <sm:p-10px dark:bg-v-dark relative">
        <div class="flex justify-between items-center text-white @2xl:justify-end @xl:justify-end">
          <div class="flex items-center @2xl:hidden @xl:hidden">
            <img
              :src="basicStore.getLogin?.image || basicStore.getHeader?.image"
              alt=""
              class="h-32px mr-10px"
            />
            <span class="text-20px font-bold">{{ underlineToHump(basicStore.getTitle) }}</span>
          </div>

          <div class="flex justify-end items-center space-x-10px">
            <ThemeSwitch />
            <!-- <LocaleDropdown class="<xl:text-white dark:text-white" /> -->
          </div>
        </div>
        <Transition appear enter-active-class="animate__animated animate__bounceInRight">
          <div
            class="h-full flex items-center m-auto overflow-auto w-[100%] @2xl:max-w-500px @xl:max-w-500px @md:max-w-500px @lg:max-w-500px"
          >
            <ResetForm
              v-if="pageStatus === 2"
              style="background-color: var(--el-bg-color)"
              :style="
                appStore.getIsDark
                  ? basicStore.getLogin?.panelStyleDark
                  : basicStore.getLogin?.panelStyle
              "
              class="p-20px h-auto m-auto <xl:(rounded-3xl light:bg-white) bg-gray-100 bg-opacity-20 dark:bg-gray-900 dark:bg-opacity-60"
              @to-login="toLogin"
            />
            <RegisterForm
              v-else-if="pageStatus === 1"
              style="background-color: var(--el-bg-color)"
              :style="
                appStore.getIsDark
                  ? basicStore.getLogin?.panelStyleDark
                  : basicStore.getLogin?.panelStyle
              "
              class="p-20px h-auto m-auto <xl:(rounded-3xl light:bg-white)"
              @to-login="toLogin"
            />
            <LoginForm
              v-else
              style="background-color: var(--el-bg-color)"
              :style="
                appStore.getIsDark
                  ? basicStore.getLogin?.panelStyleDark
                  : basicStore.getLogin?.panelStyle
              "
              class="p-20px h-auto m-auto <xl:(rounded-3xl light:bg-white) bg-gray-100 bg-opacity-20 dark:bg-gray-900 dark:bg-opacity-60"
              @to-register="toRegister"
              @to-reseter="toReseter"
            />
          </div>
        </Transition>
      </div>
    </div>
  </div>
</template>

<style lang="less" scoped>
@prefix-cls: ~'@{namespace}-login';

.@{prefix-cls} {
  &__left {
    &::before {
      position: absolute;
      top: 0;
      left: 0;
      z-index: -1;
      width: 100%;
      height: 100%;
      background-image: url('@/assets/svgs/login-bg.svg');
      background-position: center;
      background-repeat: no-repeat;
      content: '';
    }
  }
}
.login-bg {
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
}
</style>
